package com.jzo2o.customer.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jzo2o.customer.mapper.BankAccountMapper;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.IBankAccountService;
import com.jzo2o.mvc.utils.UserContext;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author lizhijun
 * @description 针对表【bank_account(银行账户)】的数据库操作Service实现
 * @createDate 2025-09-26 20:41:24
 */
@Service
public class BankAccountServiceImpl extends ServiceImpl<BankAccountMapper, BankAccount>
        implements IBankAccountService {
    //账号类型 2：服务人员，3：服务机构
    public static final Integer SERVICE_PERSON_TYPE = 2;
    public static final Integer SERVICE_AGENCY_TYPE = 3;

    /**
     * 添加或更新银行卡信息
     *
     * @param bankAccountUpsertReqDTO
     */
    @Override
    public void saveOrUpdateBankAccount(BankAccountUpsertReqDTO bankAccountUpsertReqDTO) {
        BankAccount bankAccount = new BankAccount();
        BeanUtils.copyProperties(bankAccountUpsertReqDTO, bankAccount);
        bankAccount.setId(UserContext.currentUserId());
        super.saveOrUpdate(bankAccount);
    }

    @Override
    public BankAccountResDTO getCurrentUserBankAccount() {
        BankAccount byId = super.getById(UserContext.currentUserId());
        return BeanUtil.toBean(byId, BankAccountResDTO.class);
    }
}




